#ifndef		__SERVER_H__
#define		__SERVER_H__

#include	<sys/select.h>
#include	<sys/time.h>
#include	<sys/types.h>
#include	<sys/socket.h>
#include	<arpa/inet.h>
#include	<unistd.h>
#include	<stdio.h>
#include	<stdlib.h>

#define	FD_FREE		0
#define	FD_CLIENT	1
#define	FD_SERVER	2
#define	MAX_FD		50

typedef void	(*ptrfunc)();

typedef struct	s_fdc
{
  char		fd_type[MAX_FD];
  ptrfunc	fct_read[MAX_FD];
  ptrfunc	fct_write[MAX_FD];
  int		port;
}		t_fdc;

/* init.c */
void		init_client(t_fdc *fdc, int s);
void		init_server(t_fdc *fdc);

/* read.c */
void		server_read(t_fdc *fdc, int fd);
void		client_read(t_fdc *fdc, int fd);

/* xfunc.c */
int		xsocket(int domain, int type, int protocol);
int		xbind(int sockfd, struct sockaddr *addr, socklen_t addrlen);
int		xconnect(int sockfd, struct sockaddr *addr, socklen_t addrlen);
int		xlisten(int sockfd, int backlog);
int		xaccept(int sockfd, struct sockaddr *addr, socklen_t *addrlen);

/* xfunc2.c */
ssize_t		xread(int fd, void *buf, size_t count);
ssize_t		xwrite(int fd, const void *buf, size_t count);
int		xopen(const char *pathname, int flags);
void		*xmalloc(size_t size);
void		xfree(void *ptr);

/* xfunc3.c */
int		xclose(int fd);
int		xselect(int nfds, fd_set *readfds, fd_set *writefds, fd_set *exceptfds, struct timeval *timeout);

#endif

